﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Algorithms.Evolution;
using Nage.Algorithms.Population;
using Nage.Algorithms.RandomGenerators;
using Nage.Examples.Rastrigin.Solution;

namespace Nage.Examples.Rastrigin.Evolution
{
    public class CoordinatesRecombination : ISolutionRecombination<Coordinates>
    {
        public Coordinates Recombine(Coordinates solutionA, Coordinates solutionB)
        {
            Coordinates result = null;
            double rand = Rng.GetInstance().GetDouble(4);
            if (rand <= 1)
            {
                result = new Coordinates(solutionA.X, solutionA.Y);
            }
            else if (rand <= 2)
            {
                result = new Coordinates(solutionA.X, solutionB.Y);
            }
            else if (rand <= 3)
            {
                result = new Coordinates(solutionB.X, solutionA.Y);
            }
            else
            {
                result = new Coordinates(solutionB.X, solutionB.Y);
            }
            return result;
        }
    }
}
